package com.example.ticket.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.ticket.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface UserMapper extends BaseMapper<User> {
    //用户列表
    @Select("select * from t_user")
    public List<User> Userlist();

    //检查邮箱
    @Select("select * from t_user where email=#{email}")
    public User checkEmail(String email);

    //id查用户信息
    @Select("select * from t_user where id=#{id}")
    public User selectById(Integer id);

    //重置密码
    @Update("update t_user set password=#{password} where username=#{username}")
    public int ResetPassowrd(String password,String username);

    //用户名查信息
    @Select("select * from t_user where username=#{username}")
    public User selectByUsername(String username);

    //用户名查信息
    @Select("select * from t_user where username like concat('%',#{username},'%') ")
    public List<User> findByUsername(String username);


    //ID删用户
    @Delete("delete from t_user where id=#{id}")
    public int deleteById(Integer id);

    //冻结or激活用户
    @Update("update t_user set status=#{status} where id=#{id}")
    public int freezeById(Integer status,Integer id);

    //改用户名信息
    @Update("update t_user set username=#{username},email=#{email} where id=#{id}")
    public int updateUser(User user);


    //添加用户/注册
/*    @Insert("insert into t_user(username,password,email) values(#{username},#{password},#{email})")
    public int insertUser(String username,String password,String email);*/
    @Insert("insert into t_user(username,password,email,code) values(#{username},#{password},#{email},#{code})")
    public int insertUser(User user);

    //关联用户-权限
    @Insert("insert into t_user_authority(user_id) values(#{id})")
    public int insertUserAuthority(Integer id);

    //点击邮箱中的激活码进行激活，根据激活码查询用户，之后再进行修改用户状态为1进行激活
    @Select("select * from t_user where code = #{code}")
    public User checkCode(String code);
}
